//
//  RefreshBottomView.m
//
//  Copyright (c) 2014 YDJ ( https://github.com/ydj/RefreshControl )
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.



#import "RefreshBottomView.h"
#import "CTHeader.h"
#import "CTAppLanguage.h"
#import "CTDebugManager.h"

@interface RefreshBottomView ()
{
    UIImageView * pullImageView;
}

@end

@implementation RefreshBottomView

- (void)dealloc
{
    
}
- (void)layoutSubviews
{
    
    [super layoutSubviews];
    
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        [self initViews];
    }
    return self;
}

- (void)initViews
{

    

    _activityIndicatorView=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _activityIndicatorView.hidesWhenStopped=YES;
//    _activityIndicatorView.color=[UIColor orangeColor];
    _activityIndicatorView.frame = CGRectMake((CT_HEADER_SCREEN_WIDTH - 100)/2.0-5, 34, 0, 0);
    [self addSubview:_activityIndicatorView];
    
    _loadingLabel=[[UILabel alloc] initWithFrame:CGRectMake((CT_HEADER_SCREEN_WIDTH - 100)/2.0, 25, 100, 18)];
    _loadingLabel.backgroundColor=[UIColor clearColor];
    _loadingLabel.font=[UIFont systemFontOfSize:18];
    _loadingLabel.textAlignment=NSTextAlignmentCenter;
    _loadingLabel.textColor = CT_HEADER_GREEN_COLOR;
    _loadingLabel.text = [CTAppLanguage localizedStringForKey:@"refresh_control_pullup_one" withValue:nil withTable:@"Language"];
    [self addSubview:_loadingLabel];
    
    pullImageView = [[UIImageView alloc] initWithFrame:CGRectMake((CT_HEADER_SCREEN_WIDTH - 100)/2.0-15, 30, 12, 7)];
    pullImageView.image = [UIImage imageNamed:@"xiala"];
    [self addSubview:pullImageView];
    
    
    _promptLabel=[[UILabel alloc] initWithFrame:CGRectMake((CT_HEADER_SCREEN_WIDTH - 100)/2.0, 25+18+10, 100, 18)];
    _promptLabel.backgroundColor=[UIColor clearColor];
    _promptLabel.font=[UIFont systemFontOfSize:18];
    _promptLabel.hidden = YES;
    _promptLabel.textAlignment=NSTextAlignmentCenter;
    _promptLabel.textColor = [UIColor colorWithRed:164/255.0 green:164/255.0  blue:164/255.0  alpha:1.0];
    [self addSubview:_promptLabel];
    

    
  //  [self resetViews];
    
    [self resetLayoutSubViews];

}

- (void)resetViews
{
//    _promptLabel.hidden=NO;
//    _promptLabel.text=@"上拉加载更多";
//    
//    _loadingLabel.hidden=YES;
//    _loadingLabel.text=@"正在加载...";
    
//    if ([self.activityIndicatorView isAnimating])
//    {
//        [self.activityIndicatorView stopAnimating];
//    }
    [CTDebugManager showDebugLogInfo:@"resset view"];
}


- (void)resetLayoutSubViews
{
    NSArray * tempContraint=self.constraints;
    if ([tempContraint count]>0)
    {
        [self removeConstraints:tempContraint];
    }
    
}
///松开可刷新
- (void)canEngageRefresh
{
   // _promptLabel.text=[CTAppLanguage localizedStringForKey:@"refresh_control_pullup_two" withValue:nil withTable:@"Language"];
    
}
///松开返回
- (void)didDisengageRefresh
{
   // [self resetViews];
}
///开始刷新
- (void)startRefreshing
{
    pullImageView.hidden = YES;
    _loadingLabel.textColor = [UIColor colorWithRed:164/255.0 green:164/255.0  blue:164/255.0  alpha:1.0];
    _loadingLabel.text = [CTAppLanguage localizedStringForKey:@"refresh_control_pullup_two" withValue:nil withTable:@"Language"];
   [self.activityIndicatorView startAnimating];
    
}
///结束
- (void)finishRefreshing
{
    pullImageView.hidden = NO;
    _loadingLabel.textColor = CT_HEADER_GREEN_COLOR;
    _loadingLabel.text = [CTAppLanguage localizedStringForKey:@"refresh_control_pullup_one" withValue:nil withTable:@"Language"];
    [self.activityIndicatorView stopAnimating];
   
  //  [self resetViews];
}


#pragma mark - setter -

-(void)setPullImage:(UIImage *)img
{
    pullImageView.image = img;
}

@end

// 版权属于原作者
// http://code4app.com (cn) http://code4app.net (en)
// 发布代码于最专业的源码分享网站: Code4App.com 
